from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from options import options

url=r'http://192.168.126.131/upload/'
driver=webdriver.Chrome(options=options)
driver.get(url)
driver.maximize_window()
sleep(1)

# 登录
driver.find_element(By.ID,'ls_username').clear()
sleep(2)
driver.find_element(By.ID,'ls_username').send_keys('admin')
driver.find_element(By.ID,'ls_password').clear()
sleep(2)
driver.find_element(By.ID,'ls_password').send_keys('123456')
sleep(3)
driver.find_element(By.XPATH,'//*[@id="lsform"]/div/div/table/tbody/tr[2]/td[3]/button/em').click()
sleep(3)

# 发帖

#进入默认板块
driver.find_element(By.LINK_TEXT,'默认版块').click()
sleep(3)
#发帖
driver.find_element(By.ID,'newspecial').click()
sleep(1)
#写入题目
driver.find_element(By.ID,'subject').clear()
driver.find_element(By.ID,'subject').send_keys('这是一次自动化发帖')
sleep(2)
#写入内容
# 注意：嵌套页面的处理
#跳转到碎片页面
driver.switch_to.frame('e_iframe')
driver.find_element(By.XPATH,'/html/body').clear()
driver.find_element(By.XPATH,'/html/body').send_keys('这是本次发帖的内容呦！')
sleep(2)
#跳回默认页面
driver.switch_to.default_content()
driver.find_element(By.XPATH,'//*[@id="postsubmit"]').click()
sleep(3)

# 退出
driver.find_element(By.LINK_TEXT, '退出').click()
sleep(3)

driver.quit()


